package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.service.FileUploadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * ClassName: FileController
 * Package: com.atguigu.gmall.product.controller
 * Description:
 *
 * @Author ltystart
 * @Create 2025/8/21 9:08
 * @Version 1.0
 */
@Api(tags = "文件上传接口")
@RestController
@RequestMapping("/admin/product")
public class FileController {
    @Autowired
    private FileUploadService fileUploadService;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @ApiOperation("文件上传")
    @PostMapping("/fileUpload")
    public Result upload(@RequestPart("file") MultipartFile file) throws Exception{
        System.out.println("文件名：" + file.getOriginalFilename());
        System.out.println("文件大小：" + file.getSize());
        String url = fileUploadService.upload(file);
        return Result.ok(url);
    }
}
